﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public float moveSpeed = 10;
    public float roundSpeed = 40;
    private Vector3 nowMoveDir = Vector3.zero;
    /// <summary>
    /// 开火方法
    /// </summary>
    public void Fire()
    {
        //动态创建子弹对象
        Instantiate(Resources.Load<GameObject>("Prefab/Bullet"), this.transform.position, this.transform.rotation);
    }

    public void Move(Vector2 dir)
    {
        nowMoveDir.x = dir.x;
        nowMoveDir.y = 0;
        nowMoveDir.z = dir.y;
    }

     
    private void Update()
    {
        if (nowMoveDir != Vector3.zero)
        {
            //朝面朝向移动
            this.transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
            //不停的朝目标方向转向
            this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(nowMoveDir), roundSpeed * Time.deltaTime);
        }
    }
}
